﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Mate.Caching;
using Mate.Core.Base;
using Mate.Framework.BaseController.Admin;
using Mate.Framework.Extensions;
using Mate.Framework.Infrastructure;
using Mate.System.Service;
using Microsoft.AspNetCore.Mvc;

namespace Mate.Admin.Controllers
{
    public class HomeController : BaseController
    {
        private readonly IRolesService rolesService;
        private readonly ICacheManager _cache;
        public HomeController(IRolesService rolesService, ICacheManager cache)
        {
            this.rolesService = rolesService;
            this._cache = cache;
        }

        [NonAuthorization]
        public ActionResult Index()
        {
            ViewBag.FullName = HttpContext.User.Identity.UserName();
            return View();
        }

        #region 欢迎页面
        [NonAuthorization]
        public ActionResult Welcome()
        {
            return View();
        }
        #endregion

        #region 错误页面
        [NonAuthorization]
        public ActionResult Error()
        {
            return View();
        }
        #endregion


        #region 获取所有菜单
        /// <summary>
        /// 获取所有菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [NonAuthorization]
        public JsonResult GetMenu()
        {
            var result = rolesService.GetNavAll(HttpContext.User.Identity.RoleId(), IsSuperAdmin);
            return Json(result);
        }
        #endregion


        #region 没有权限页面
        [NonAuthorization]
        public ActionResult Unauthorized()
        {
            return View();
        }
        #endregion


        //#region 清除缓存
        //[NonAuthorization]
        //public JsonResult ClearCache()
        //{
        //    var result = new BaseResult();
        //    try
        //    {
        //        _cache.RemoveAll();
        //        result.IsSuccess = true;
        //        result.Message = "清除缓存成功";
        //    }
        //    catch (Exception ex)
        //    {
        //        result.IsSuccess = false;
        //        result.Message = "清除缓存失败";
        //    }
        //    return Json(result);
        //}
        //#endregion

        //#region 解锁
        //[HttpPost]
        //[NonAuthorization]
        //public JsonResult Unlock(string pwd)
        //{
        //    var result = new BaseResult();
        //    if (pwd == CurrentAdminUser.Password)
        //    {
        //        result.IsSuccess = true;
        //    }
        //    else
        //    {
        //        result.IsSuccess = false;
        //        result.Message = "密码错误";
        //    }
        //    return Json(result);
        //}
        //#endregion

    }
}